﻿using System.Collections.ObjectModel;
using System.Windows.Input;
using Microsoft.Expression.Interactivity.Core;
using QDP.Platform.Silverlight;
using QDP.Platform.Services;
namespace Apps.Common
{
    public class MessageTipWidget : PartElement
    {
        private MessageTip widget;
        private string tileText;
        private ObservableCollection<MessageContract> _Messages;
        public MessageTipWidget()
        {
            WidgetContent = widget = new MessageTip();
            Messages = new ObservableCollection<MessageContract>();
            widget.Messaged += new System.EventHandler<MessageEventArgs>(widget_Messaged);
            TileText = ":-)";
            ViewCommand = new ActionCommand(this.viewCommand);
        }

        void widget_Messaged(object sender, MessageEventArgs e)
        {
            Messages.Add(e.Message);
            if (Messages.Count > 2)
                TileText = ";-)";
            if (Messages.Count > 5)
                TileText = ";-O";
            this.Show();
        }
        private void viewCommand()
        {
            //MessageBox.Show("1");
        }
        public override void Show()
        {
            this.IsShowed = true;
        }
        public override void Close()
        {
            this.IsShowed = false;
        }
        public ICommand ViewCommand { get; private set; }
        public string TileText
        {
            get
            {
                return tileText;
            }
            set
            {
                if (tileText != value)
                {
                    tileText = value;
                    Notify("TileText");
                }
            }
        }
        public ObservableCollection<MessageContract> Messages
        {
            get 
            {
                return _Messages; 
            }
            set
            {
                if (_Messages != value)
                {
                    _Messages = value;
                    Notify("Messages");
                }
            }
        }
    }
}